<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>rbfpreimg3.m</title>
<link rel="stylesheet" type="text/css" href="../../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>x&nbsp;</span>=&nbsp;<span class=defun_name>rbfpreimg3</span>(<span class=defun_in>model,nn</span>)<br>
<span class=h1>%&nbsp;RBFPREIMG3&nbsp;RBF&nbsp;pre-image&nbsp;problem&nbsp;by&nbsp;Kwok-Tsang's&nbsp;algorithm.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;x&nbsp;=&nbsp;rbfpreimg3(model)</span><br>
<span class=help>%&nbsp;&nbsp;x&nbsp;=&nbsp;rbfpreimg3(model,nn)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;x&nbsp;=&nbsp;rbfpreimg3(model)&nbsp;is&nbsp;an&nbsp;implementation&nbsp;of&nbsp;the&nbsp;algorithm&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;by&nbsp;[Kwok03]&nbsp;to&nbsp;solve&nbsp;the&nbsp;pre-image&nbsp;problem&nbsp;for&nbsp;kernel&nbsp;expansion&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;with&nbsp;RBF&nbsp;kernel.&nbsp;The&nbsp;kernel&nbsp;expansion&nbsp;is&nbsp;given&nbsp;in&nbsp;the&nbsp;input&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;structure&nbsp;model.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;x&nbsp;=&nbsp;rbfpreimg3(model,nn)&nbsp;use&nbsp;to&nbsp;set&nbsp;number&nbsp;of&nbsp;nearest&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;neighbours&nbsp;(default&nbsp;10).</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;[struct]&nbsp;RBF&nbsp;kernel&nbsp;expansion:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.Alpha&nbsp;[nsv&nbsp;x&nbsp;1]&nbsp;Weights.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.sv.X&nbsp;[dim&nbsp;x&nbsp;nsv]&nbsp;Vectors.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.options.arg&nbsp;[1x1]&nbsp;RBF&nbsp;kernel&nbsp;width.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;nn&nbsp;[1x1]&nbsp;Number&nbsp;of&nbsp;nearest&nbsp;neighbours.</span><br>
<span class=help>%&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;x&nbsp;[dim&nbsp;x&nbsp;1]&nbsp;Pre-image&nbsp;of&nbsp;the&nbsp;RBF&nbsp;kernel&nbsp;expansion.</span><br>
<span class=help>%&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;RBFPREIMG1,&nbsp;RBFPREIMG2,&nbsp;RSRBF,&nbsp;KPCAREC.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;17-may-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;21-Feb-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;17-February-2004,&nbsp;Petr&nbsp;Posik</span><br>
<br>
<hr>
[dim,&nbsp;num_data]&nbsp;=&nbsp;size(model.sv.X);<br>
<br>
<span class=comment>%&nbsp;default&nbsp;number&nbsp;of&nbsp;used&nbsp;nearest&nbsp;neighbours&nbsp;</span><br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;&lt;&nbsp;2,&nbsp;nn&nbsp;=&nbsp;min([num_data,&nbsp;10]);&nbsp;<span class=keyword>end</span><br>
<br>
K&nbsp;=&nbsp;kernel(model.sv.X,&nbsp;<span class=quotes>'rbf'</span>,&nbsp;model.options.arg&nbsp;);<br>
<br>
Const2&nbsp;=&nbsp;model.Alpha(:)'*K*model.Alpha(:);<br>
df2&nbsp;=&nbsp;1&nbsp;+&nbsp;Const2&nbsp;-&nbsp;2*K*model.Alpha(:);<br>
d2&nbsp;=&nbsp;-2*model.options.arg^2&nbsp;*&nbsp;log(&nbsp;1&nbsp;-&nbsp;0.5*df2);<br>
<br>
<span class=comment>%&nbsp;select&nbsp;nn&nbsp;neighbours</span><br>
[dummy,&nbsp;inx]&nbsp;=&nbsp;sort(&nbsp;df2&nbsp;);<br>
X&nbsp;=&nbsp;model.sv.X(:,inx(1:nn));<br>
df2&nbsp;=&nbsp;df2(inx(1:nn));<br>
d2&nbsp;=&nbsp;d2(inx(1:nn));<br>
<br>
H&nbsp;=&nbsp;eye(nn,nn)&nbsp;-&nbsp;1/nn&nbsp;*&nbsp;ones(nn,nn);<br>
<br>
[U,L,V]&nbsp;=&nbsp;svd(X*H);<br>
r&nbsp;=&nbsp;rank(L);<br>
<br>
Z&nbsp;=&nbsp;L*V';<br>
<br>
d02&nbsp;=&nbsp;sum(Z.^2)';<br>
<br>
z&nbsp;=&nbsp;-0.5*pinv(Z')*(d2-d02);<br>
x&nbsp;=&nbsp;U*z&nbsp;+&nbsp;sum(X,2)/nn;<br>
<br>
<span class=jump>return</span>;<br>
<br>
</code>
